package study.chapter03.thread.daemon;

//守护线程
public class TestThread {
    public static void main(String[] args) {
        //用户线程
        Thread userThread = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                System.out.println(Thread.currentThread().getName() + "在运行：" + i);
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "用户线程");

        //守护线程
        Thread daemonThread = new Thread(() -> {
            for (int i = 0; i < Integer.MAX_VALUE; i++) {
                System.out.println(Thread.currentThread().getName() + "在运行：" + i);
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "守护线程");
        daemonThread.setDaemon(true);
        userThread.start();
        daemonThread.start();
    }
}
